package org.liveboardgames.agricola.vo
{
    import com.adobe.cairngorm.vo.IValueObject;
    
    import mx.collections.ArrayCollection;
    import mx.collections.ListCollectionView;
    
    import org.liveboardgames.agricola.vo.card.Card;
    import org.liveboardgames.agricola.vo.card.ImprovementCard;
    import org.liveboardgames.agricola.vo.player.Player;
    
    [RemoteClass(alias="org.liveboardgames.agricola.domain.Game")]
    [Bindable]
    public class Game implements IValueObject
    {
    	public var id:int;
    	
        /**
         * The players that participate in the game. The list is
         * ordered, and thus it is used to define the order in
         * which the players take turns.
         */
        public var players:ListCollectionView;
        
        public var harvestFieldPlayers:ListCollectionView = new ArrayCollection();
        public var harvestFeedPlayers:ListCollectionView = new ArrayCollection();
        public var harvestBreedPlayers:ListCollectionView = new ArrayCollection();
        
        /**
         * The list of all the tiles in the board. The list is
         * ordered, which matches the order of the tiles in the
         * original board. They are counted from top to bottom,
         * starting from the left and counting column after column.
         */
        public var tiles:ListCollectionView;
        
        /**
         * The player whose turn it is to play.
         */
        public var currentPlayer:Player;
        
        /**
         * A boolean that indicates whether the player has already
         * player their peep.
         * TODO: Not really cool design though.
         * TODO: this may not really be part of the game itself, but rather the
         * state of the game.
         */
        public var hasPlayerPlayedPeep:Boolean;
        
        /**
         * The list of actions that are turned face up each turn.
         */
        public var waitingActionCards:ListCollectionView;
        
        /**
         * The list of all the major improvements that have not been
         * built yet.
         */
        public var majorImprovements:ListCollectionView;
        
        public var isFinished:Boolean;
        
        public function addMajorImprovement(card:ImprovementCard):void
        {
            if (this.majorImprovements == null)
            {
                this.majorImprovements = new ArrayCollection();
            }
            this.majorImprovements.addItem(card);
        }
        
        public function removeMajorImprovementById(cardId:int):void
        {
        	if (this.majorImprovements != null)
        	{
        		var index:int;
        		for each (var majorImprovement:Card in this.majorImprovements)
        		{
        			if (majorImprovement.cardId == cardId)
        			{
        				index = this.majorImprovements.getItemIndex(majorImprovement);
        			}
        		}
        		this.majorImprovements.removeItemAt(index);
        	}
        }
    }
}